from selenium.webdriver.common.action_chains import ActionChains
from selenium import webdriver
from selenium import webdriver
from selenium.webdriver.edge.service import Service
from selenium.webdriver.edge.options import Options
import time
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from lib.seleniumHelper import web_Auto_Helper
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC


tester = web_Auto_Helper()


input1 = tester.browser.find_element(
    By.XPATH, '//*[@class="tabs-item-text" and text()="手机号登录"]')
input1.click()

# 切换到 iframe
iframe = tester.browser.find_element(
    By.XPATH, '//div[@id="alibaba-mobile-login-iframe"]//iframe')
print(iframe, type(iframe))
tester.browser.switch_to.frame(iframe)

# 手机号
input1 = tester.browser.find_element(
    By.XPATH, '//input[@name="fm-sms-login-id"]')
input1.clear()
input1.click()
input1.send_keys('18159881915')
input1.send_keys(Keys.RETURN)

# 同意勾选按钮
button = tester.browser.find_element(
    By.XPATH, '//input[@type="checkbox"]')

# 使用 ActionChains 移动到按钮并点击
actions = ActionChains(tester.browser)
actions.move_to_element(button).click().perform()

input1.click()


# 获取验证码btn
input1 = tester.browser.find_element(
    By.XPATH, '//div[@class="send-btn"]')
input1.click()
time.sleep(20)

# 输入验证码
# input1 = tester.browser.find_element(
#     By.XPATH, '//input[@name="fm-smscode"]')
# input1.click()
# input1.send_keys('22')

# 切回主文档
tester.browser.switch_to.default_content()
# input1.send_keys('18159881915')
